<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <ui:composition template="layout.xhtml">

        <ui:define name="corpo">
            <h:form>
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  value="Protocolo" update="@form" immediate="true"/>

                </div>

            </h:form>
            <p:panel header="Principal - Protocolo">
                <table style="min-height:500px; width: 100%">
                    <tr>
                        <td>
                            <ui:include src="menuProtocolo.xhtml"/>
                        </td>
                        <td style="vertical-align:top;">
                            <h:form id="index_form" style="vertical-align: top" acceptcharset="utf-8"> 
                                <p:panel header="Pesquisar Protocolo">
                                    <p:growl showDetail="true"  id="msg" life="2000" /> 
                                    <h:panelGrid columns="2" id="panelGridEscolha" styleClass="textAlignRight" columnClasses="textAlignRight">

                                        <h:outputLabel value="Cód. Protocolo: " />
                                        <f:validateBean disabled="true">
                                            <p:inputText  value="#{managerConsultarProtocolo.protocolo.id}" size="20"/>
                                        </f:validateBean>

                                        <h:outputLabel value="Cliente: "/>
                                        <p:autoComplete id="cliente" value="#{managerConsultarProtocolo.protocolo.cliente}" completeMethod="#{managerPessoa.autoComplete}"  
                                                        var="c" itemLabel="#{c.nome}" itemValue="#{c}" converter="pessoaConverter" forceSelection="true" converterMessage="Erro, verifique o Cliente" minQueryLength="3" dropdown="true"> 
                                        </p:autoComplete>

                                        <h:outputLabel value="Data :"/>
                                        <p:calendar value="#{managerConsultarProtocolo.protocolo.dataCad}"  mode="popup" showOn="both" pattern="dd/MM/yyyy" />
                                        <h:outputLabel />
                                        <p:column>

                                        </p:column>
                                    </h:panelGrid> 
                                    <center>
                                        <p:commandButton value="Buscar" icon="ui-icon-search" actionListener="#{managerConsultarProtocolo.buscar()}" update="@form, protocoloTable, msg"/>
                                        <p:commandButton value="Limpar" icon="ui-icon-circle-close" actionListener="#{managerConsultarProtocolo.init()}" update="@form, protocoloTable, msg"/>
                                    </center>
                                    <br/>
                                    <p:dataTable id="protocoloTable" var="protocolo" value="#{managerConsultarProtocolo.protocolos}" 
                                                 paginator="true" rows="5"
                                                 paginatorPosition="bottom"
                                                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                                 rowsPerPageTemplate="5,10,15"
                                                 emptyMessage="Nenhum Registro Encontrado">    

                                        <f:facet name="header">  
                                            Dados Protocolos
                                        </f:facet>

                                        <p:column  style="width:5px;" >  
                                            <p:rowToggler/>
                                        </p:column>

                                        <p:column  style="width:100px;">  
                                            <f:facet name="header" >   
                                                Código
                                            </f:facet>  
                                            <h:outputText value="#{protocolo.id}" style="font-weight: bold;"  />  
                                        </p:column>

                                        <p:column  style="width:300px;">  
                                            <f:facet name="header" >   
                                                Cliente
                                            </f:facet>  
                                            <h:outputText value="#{protocolo.cliente.nome}" style="font-weight: bold;"  />  
                                        </p:column>


                                        <p:column  style="width:150px;">  
                                            <f:facet name="header" >   
                                                Data
                                            </f:facet>  
                                            <h:outputText value="#{protocolo.dataCad}" style="font-weight: bold;">
                                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
                                            </h:outputText>  
                                        </p:column>

                                        <p:column  style="width:100px;">  
                                            <f:facet name="header" >   
                                                Valor
                                            </f:facet>  
                                            <h:outputText value="#{managerConsultarProtocolo.valorDoProtocolo(protocolo)}" style="font-weight: bold;" />  
                                        </p:column>

                                        <p:column  style="width:50px;">  
                                            <f:facet name="header" >   
                                                Situação
                                            </f:facet>  
                                            <h:outputText value="#{protocolo.ativo ? 'Ativo' : 'Inativo'}" style="font-weight: bold;" />  
                                        </p:column>

                                        <p:rowExpansion>
                                            <h:outputLabel value="Serviços do Protocolo" style="font-weight: bold;"/>
                                            <table style="width:100%">
                                                <tbody style="background-color: #5277A9; color: #ffffff; ">
                                                    <td style="font-weight: bold; text-align: center;">
                                                        Ato Item
                                                    </td>
                                                    <td style="font-weight: bold; text-align: center;">
                                                        Cartório
                                                    </td>
                                                    <td style="font-weight: bold; text-align: center;">
                                                        Fermojupi
                                                    </td>
                                                    <td style="font-weight: bold; text-align: center;" >
                                                        Valor
                                                    </td>

                                                </tbody>
                                                <ui:repeat value="#{protocolo.servicoProtocolos}" var="servico">
                                                    <tr>
                                                        <td style="text-align: center;">
                                                            <h:outputLabel value="#{servico.atoItem.codigo}" /> - 
                                                            <h:outputLabel value="#{servico.atoItem.descricao}" /></td>
                                                        <td style="text-align: center;"><h:outputLabel value="#{servico.valorCartorio}" /></td>
                                                        <td style="text-align: center;" ><h:outputLabel value="#{servico.valorFermojupi}" /></td>
                                                        <td style="text-align: center;"><h:outputLabel value="#{servico.valor}" /></td>
                                                    </tr>
                                                </ui:repeat>

                                            </table>

                                        </p:rowExpansion>
                                    </p:dataTable> 
                                    <br/>
                                    <center>
                                        <p:commandButton id="limpar" icon="ui-icon-arrowreturnthick-1-w" value="Cancelar" actionListener="#{managerConsultarProtocolo.redirect('protocolo.xhtml')}" immediate="true" />
                                    </center> 
                                </p:panel>
                            </h:form>
                        </td>
                    </tr>
                </table>
            </p:panel>
        </ui:define>
    </ui:composition>
</html>

